﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Comment.aspx.cs" Inherits="SF.Dict.Web.Comment" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Src="UserControls/ucVocHeader.ascx" TagName="ucVocHeader" TagPrefix="uc3" %>
<%@ Register Src="UserControls/ucVocAside.ascx" TagName="ucVocAside" TagPrefix="uc2" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
	<title>
		<asp:Literal runat="server" ID="ll_title"></asp:Literal></title>
	<script type="text/javascript" src="/Common/jquery-1.3.2.js"></script>
	<script type="text/javascript" src="/Common/base.js"></script>
	<script type="text/javascript">

		$(document).ready(
			function () {

				$(".feed:last-child").addClass("last");

				$('.feed').hover(
					function () {
						if ($('#' + $(this).attr('id') + '_r').css('display') != 'none') {
							return;
						}
						$('#' + $(this).attr('id') + '_o').removeClass('hide');
					},
					function () {
						if ($('#' + $(this).attr('id') + '_r').css('display') != 'none') {
							return;
						}
						$('#' + $(this).attr('id') + '_o').addClass('hide');
					}
				);

				$.each($('.feed-act > a'), function () {
					var txt = $(this).text();
					var cid = $(this).parent().attr('data-id');
					if (txt.indexOf('评论') != -1) {

						$(this).click(function () {
							var rdom = $('#ct_' + cid + '_r');
							rdom.toggle();
							if (rdom.html().trim() == '') {

								var sb = new StringBuffer();
								sb.Append('<div class="feed-ft-triangle"></div>');
								sb.Append('<div class="feed-comment">');
								sb.Append('	<div class="cmt-holder">');
								sb.Append('		<div><textarea id="ct_{cid}_r_c" class="cmt"></textarea></div>');
								sb.Append('			<div id="ct_{cid}_r_d" style="margin-top: 5px;">');
								sb.Append('			<input id="ct_{cid}_r_b" type="button" class="btn" value="提交" />');
								sb.Append('			&nbsp;&nbsp;&nbsp;&nbsp;<a  class="anb" onclick="CancelCmt({cid},1);" href="javascript:void(0)">取消</a>');
								sb.Append('			&nbsp;&nbsp;(你还可输入<span id="rlen">250</span>字)');
								sb.Append('		</div>');
								sb.Append('	</div>');
								sb.Append('	<ul class="cmt-list" id="ct_{cid}_r_u"></ul>');
								sb.Append('</div>');

								rdom.append(sb.toString().replace(/\{cid\}/gim, cid));

								$('#ct_' + cid + '_r_b').bind("click", { fun: SubmitReplay, title: "操作成功", argus: { cid: cid, again: false} }, ShowMiniHint);

								GetReview(cid, false);
							}
						});
					}
					else if (txt == '删除') {

					}
					else if (txt == '屏蔽') {

					}
				});
			}
		);

		//取消评论执行操作
		function CancelCmt(id, mum) {
			$('#ct_' + id + '_r').hide();
		}

		function GetReview(cid, again) {
			$.ajax({
				url: '/Submit/submit.ashx?action=003&cid=' + cid + '&rnd=' + Math.random(),
				type: 'GET',
				timeout: 5000,
				dataType: "json",
				error: function () {
					if (again) {
						$('#review_' + cid).html('');
					}
					else {
						$('#review_' + cid).html('加载失败，<a class="action" onclick="GetReview(' + cid + ',true)">请重试</a>');
					}
				},
				success: function (json) {
					if (json.code == 0) {
						var obj = json.obj;
						var h = obj.length;
						var rid = 'rw_' + cid;
						$('#ct_' + cid + '_r_u').html('');

						for (var i = 0; i < h; i++) {
							var csb = new StringBuffer();
							var ccid = obj[i].cid;

							csb.Append('<li id="cmt_' + ccid + '" class="clearfix' + (i == 0 ? ' first' : '') + '">');
							csb.Append('<a href=""><img class="cmt-avatar" width="20" height="20" src="' + obj[i].img + '" /></a>');
							csb.Append('<span class="cmt-main"><a class="cmt-user" href="">' + obj[i].name + '</a>&nbsp;&nbsp;<span class="cmt-content">' + obj[i].content + '</span></span>');
							csb.Append('<a class="cmt-reply action">回复</a> ');

							if (userid == obj[i].uid) {
								csb.Append('<a id="cmt_' + ccid + '_o" class="cmt-block action hide">删除</a>');
							}
							else {
								csb.Append('<a id="cmt_' + ccid + '_o" class="cmt-block action hide">屏蔽</a>');
							}

							csb.Append('</li>');

							$('#ct_' + cid + '_r_u').append(csb.toString());

							$.each($('#cmt_' + ccid + ' .cmt-block'), function () {
								var txt = $(this).text();
								if (txt == '删除') {
									$(this).bind("click", { fun: DeleteReview, title: "确认删除此评论？", argus: { cid: cid, ccid: ccid, again: false} }, ShowMiniPop);
								}
								else if (txt == '屏蔽') {
									$(this).bind("click", { fun: ScreenReview, title: "确认屏蔽此评论？", argus: { cid: cid, ccid: ccid, again: false} }, ShowMiniPop);
								}
							});

							$('#cmt_' + ccid).hover(
								function () {
									$('#' + $(this).attr('id') + '_o').removeClass('hide');
								},
								function () {
									$('#' + $(this).attr('id') + '_o').addClass('hide');
								}
							);
						}
					}
					else {
						if (again) {
							$('#review_' + cid).html('');
						}
						else {
							$('#review_' + cid).html('加载失败，<a class="action" onclick="GetReview(' + cid + ',true)">请重试</a>');
						}
					}
				}
			});
		}

		function DeleteReview() {

		}
		function ScreenReview() {

		}
		function SubmitReplay() {

		}

		function ShowMiniPop(e) {
			var holder = $('#minipop-holder');
			$('#minipop-action').show();
			$('#minipop-hint').hide();
			holder.fadeIn();
			var offset = $(this).offset();
			$('#minipop-tip').html(e.data.title);

			holder.css({
				'top': offset.top - holder.outerHeight() - 5 + 'px',
				'left': offset.left - holder.outerWidth() / 2 + 12 + 'px'
			});

			$('#minipop-submit').bind('click', e.data.argus, e.data.fun);
		}

		function ShowMiniHint(e) {
			var holder = $('#minipop-holder');
			$('#minipop-action').hide();
			$('#minipop-hint').show();
			holder.fadeIn();
			$('#minipop-hint-tip').html('<img src="/Common/images/ajax-loader.gif" style="vertical-align:middle" />&nbsp;&nbsp;正在提交...');
			var offset = $(this).offset();

			holder.css({
				'top': offset.top - holder.outerHeight() - 5 + 'px',
				'left': offset.left - holder.outerWidth() / 2 + 12 + 'px'
			});
			e.data.fun(e.data.argus);
		}

		function AddMiniHint(content) {
			$('#minipop-hint-tip').html(content);
			$('#minipop-action').hide();
			$('#minipop-hint').show();
		}

		function HideMiniPop(timeout) {
			$('#minipop-submit').unbind();
			if (timeout) {
				$('#minipop-holder').fadeOut(timeout);
			}
			else {
				$('#minipop-holder').hide();
			}
		}
	</script>
</head>
<body class="page-voc">
	<form id="form1" runat="server">
	<div id="wrap">
		<div id="control_panel">
			<a title="返回首页" class="nav-icon action return" href="/home.aspx">返回首页</a> <a title="点击关注"
				class="nav-icon action follow">关注</a> <a class="nav-icon action defined" title="自定义"
					href="javascript:void(0)">自定义</a>
		</div>
		<div id="container">
			<uc3:ucVocHeader ID="ucVocHeader1" runat="server" />
			<div id="main">
				<div id="feed-holder">
					<asp:Repeater ID="rp_comments" runat="server">
						<ItemTemplate>
							<div class="feed" id='ct_<%#Eval("CID")%>'>
								<div class="feed-avatar">
									<a class="sworn-avatar" style="background-image: url('<%#Eval("ProfileImageUrl")%>');"
										href="#">shenni</a> <a style="background-image: url('<%#Eval("ProfileImageUrl")%>');"
											class="blog-avatar" href="#">shenni</a>
								</div>
								<div class="content-holder">
									<div class="pop-triangle">
									</div>
									<div class="content">
										<div class="feed-hd">
											<a class="feed-user" href="http://www.zhshan.com">
												<%#Eval("Author")%>&nbsp;&nbsp;</a> <span>
													<%#Eval("ParentId").ToString() == Guid.Empty.ToString() ? "笔记":"评论" %></span>
										</div>
										<div class="feed-bd clearfix">
											<div class="feed-content">
												<p>
													<%#EncodeToHtml(Eval("Comment").ToString())%></p>
											</div>
											<div class="feed-dict">
												单词: <a target="_blank" href='/dict.aspx?i=<%#Eval("AID")%>'>
													<%#Eval("ANCESTORDESC")%></a>
											</div>
											<div class="feed-act" data-id='<%#Eval("CID")%>'>
												<a id='ct_<%#Eval("CID")%>_o' class="action hide">屏蔽</a>&nbsp;&nbsp; <a class="action">
													评论(<%#Eval("ChildCount")%>)</a>
											</div>
										</div>
										<div class="feed-ft" id='ct_<%#Eval("CID")%>_r'>
										</div>
									</div>
								</div>
							</div>
						</ItemTemplate>
					</asp:Repeater>
				</div>
			</div>
			<uc2:ucVocAside ID="ucVocAside1" runat="server" />
		</div>
		<div id="minipop-holder" class="hide">
			<div id="minipop-action" class="minipop">
				<div class="gray6">
					<div id="minipop-tip">
					</div>
				</div>
				<div class="btn-holder">
					<span><a id="minipop-submit" href="javascript:void(0)" class="action">确定</a></span>&nbsp;&nbsp;
					<span><a href="javascript:void(0)" onclick="HideMiniPop()" class="action">取消</a>
					</span>
				</div>
			</div>
			<div id="minipop-hint" class="minipop hide">
				<div class="gray6">
					<div id="minipop-hint-tip">
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</body>
</html>
